/*
*	ID : Pallab
* 	PROG : C
* 	LANG : C++
* 	2012-12-12-15.38.50 Wednesday
*
* 	"I have not failed, I have just found 10000 ways that won't work.
*/
#include <iostream>
#include <algorithm>
#include <vector>
#include <sstream>
#include <fstream>
#include <string>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <numeric>
#include <stack>
#include <functional>
#include <bitset>
#include <iomanip>
#include <chrono>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <ratio>
#include <chrono>

#include <ctime>
#include <cassert>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <climits>
#include <cstring>
#include <cstdlib>

using namespace std;

#define foR(i1,st,ed) for(int i1 = st , j1 = ed ; i1 < j1 ; ++i1 )
#define fo(i1,ed) foR( i1 , 0 , ed )
#define foE(i1,st,ed) foR( i1, st, ed+1 )
#define foit(i, x) for (typeof((x).begin()) i = (x).begin(); i != (x).end(); i++)
#define bip system("pause")
#define Int long long
#define pb push_back
#define SZ(X) (int)(X).size()
#define LN(X) (int)(X).length()
#define mk make_pair
#define SET( ARRAY , VALUE ) memset( ARRAY , VALUE , sizeof(ARRAY) )
#define line puts("")

inline void wait(double seconds) {
    double endtime = clock() + (seconds * CLOCKS_PER_SEC);
    while (clock() < endtime) {
        ;
    }
}
template<class T>
inline T fastIn() {
    register char c=0;
    register T a=0;
    bool neg=false;
    while(c<33)c=getchar();
    while(c>33) {
        if(c=='-') {
            neg=true;
        } else {
            a= (a*10)+(c-'0');
        }
        c=getchar();
    }
    return neg?-a:a;
}
struct node1 {
    int src[2];
    int snk[2];
    inline void read() {
        fo(i,2)src[i]=fastIn<int>()-1;
        fo(i,2)snk[i]=fastIn<int>()-1;
    }
    inline void print() {
        fo(i,2)cout<<src[i]<<'_';
        fo(i,2)cout<<snk[i]<<'_';
        puts("!");
    }
};
node1 M;
int page_count;
int page_info[105];

inline void read() {
    page_count=fastIn<int>();
    fo(i,page_count)page_info[i]=fastIn<int>();
    M.read();
    //M.print();
}
int rr[]= {-1,+1,+0,+0};
int cc[]= {+0,+0,+1,-1};

#define P pair<int, pair<int,int> >
#define MOV(X) (X).first
#define R(X) (X).second.first
#define C(X) (X).second.second

#if defined( xerxes_pc)
bool dist[100][1000];
#else
bool dist[105][100005];
#endif
struct node{
        int r,c,m;
};
using namespace std::chrono;

inline int dj() {
    queue<node> q;
    SET(dist,false);

    q.push( node{M.src[0],M.src[1],0} );
    dist[M.src[0]][M.src[1]]=true;

//    time_t start,end;
//    time(&start);

    while(q.empty()==false) {
        node f=q.front();
        q.pop();
        if(f.r==M.snk[0]&&f.c==M.snk[1])return f.m;


        fo(i,4) {
            int tr=f.r+rr[i],tc=f.c+cc[i],tm=f.m+1;
            if(tr<0||tc<0||tr>=page_count||tc>page_info[f.r])continue;
            tc=min(tc, page_info[tr]);
            if( !dist[tr][tc]) {
                dist[tr][tc]=true;
                q.push(node{tr,tc,tm});
            }
        }

    }
    return -1;
}
inline void proc() {
    int retval=dj();
    cout<<retval<<'\n';
}
int main() {
    int kase = 1;
#if defined( xerxes_pc )
    if (!freopen("in1", "r", stdin))
        puts("error opening file in "), assert(0);
    kase = 1;
#else
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#endif
    fo(i,kase) {
        read();
        proc();
    }
    return 0;
}
